package com.billing.persistance.entities;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

@Entity
@Table(name="TECH_USER")
public class TechUser implements UserDetails{

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    
    @Column (name="LOGIN")
    private String login;
    
    @Column (name="PASSWORD")
    private String password;

    @Column (name="PASSWORD_EXPIRED")
    private boolean credentialsExpired;
    
    @Column (name="LOCKED")
    private boolean locked;
    
    @Column (name="ACCOUNT_EXPIRED")
    private boolean accountExpired;
    
    @Column (name="ENABLED")
    private boolean enabled;

    @OneToMany(fetch = FetchType.EAGER, mappedBy="techUser", cascade = CascadeType.ALL)
    private Set<TechGrantedAuthority> authorities;
    
    
    public Collection<GrantedAuthority> getAuthorities() {
        return new ArrayList<GrantedAuthority>(authorities);
    }

    public String getPassword() {
        return password;
    }

    public String getUsername() {
        return login;
    }

    public boolean isAccountNonExpired() {
        return !accountExpired;
    }

    public boolean isAccountNonLocked() {
        return !locked;
    }

    public boolean isCredentialsNonExpired() {
        return !credentialsExpired;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }

}

